home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / spoc88 / pmatch / csz.sc
Text File  |  1988-07-11  |  2KB  |  77 lines

  1. ; SCRIPT:   CSZ.SC
  2. ; AUTHOR:   Bill Cusano  (516) 293-6846
  3. ; FUNCTION: Demonstrate using MATCH to parse a string
  4.  
  5.  
  6. PROC CSZSplit(CSZ)
  7.      PRIVATE x4,x5
  8.  
  9. ;           The IF statement below tests whether the string in CSZ
  10. ;           matches a given pattern.  The MATCH function performs
  11. ;           this test, and if the test passes, variables City and
  12. ;           State are assigned the values of their corresponding
  13. ;           patterns within the string.  The double dot (..) pattern
  14. ;           used here accepts any number of characters or numbers in
  15. ;           the position.
  16.  
  17.          IF MATCH(CSZ,".., ..",City,State) THEN
  18.  
  19. ;             The WHILE command below tests, in each pass through
  20. ;             the loop, that the string value of the variable State
  21. ;             matches the quoted pattern.  Here, if the string
  22. ;             contains a leading space, the loop continues.  The
  23. ;             MATCH function performs a logical test for a match
  24. ;             and, upon a match, it fills the variable x4 with all
  25. ;             characters to the right of the leading space.
  26.  
  27.               WHILE MATCH(State," ..",x4)
  28.  
  29. ;                  Each pass through the loop causes the variable
  30. ;                  State to be reassigned to the value of x4.  Thus
  31. ;                  the string loses its leading blank space.
  32.  
  33.                    State = x4
  34.  
  35.               ENDWHILE
  36.  
  37. ;             The WHILE loop above would only be run if there
  38. ;             are leading spaces in the string.  If it does
  39. ;             not run, we need to assign the value of State to
  40. ;             the variable x4, which is tested below.
  41.  
  42.               x4 = State
  43.  
  44. ;             Here, we're using MATCH again to separate out the
  45. ;             State and ZIP data from the remains of the string
  46. ;             once City has been removed.
  47.  
  48.               IF MATCH(x4,".. ..",State,Zip) THEN
  49.  
  50. ;               This WHILE statement removes leading spaces from
  51. ;               Zip:
  52.  
  53.                 WHILE MATCH(Zip," ..",x5)
  54.  
  55.                    Zip = x5
  56.  
  57.                 ENDWHILE
  58.               ENDIF
  59.          ENDIF
  60. ENDPROC
  61.  
  62. ; Below is a test program for procedure CSZSplit:
  63.  
  64. City = ""
  65. State = ""
  66. Zip = ""
  67.  
  68. @ 2,4 ? "Enter String: "   ; Enter a string to split
  69. ACCEPT "A25" TO CSZ
  70.  
  71. CSZSplit(CSZ)    ; Split city, state, and ZIP from CSZ
  72.  
  73. @ 6,4 ?? City    ; Show the three fields split from string CSZ
  74. @ 7,4 ?? State
  75. @ 8,4 ?? Zip
  76. sleep 3000
  77.